#include <iostream>
#include <vector>
#include "render.h"

class SoftRender: public Render {
public:
  SoftRender(const Intrinsics& intrinsics);
  ~SoftRender() {}

  bool AddBody(Body* body_ptr) override;
  bool DeleteBody(Body* body_ptr) override;
  void ClearBodies();

  bool RenderNormal() override;
  bool RenderSilhouette() override;

  float Depth(ushort depth_image_value) const override;
  float Depth(const cv::Point2i& image_coordinate) const override;
  Eigen::Vector3f PointVector(const cv::Point2i& image_coordinate) const override;

  bool FetchDepthImage() override;
  bool FetchNormalImage() override;
  bool FetchSilhouetteImage() override;

  void FillFace(
    const Eigen::Vector3f& v1,
    const Eigen::Vector3f& v2,
    const Eigen::Vector3f& v3,
    unsigned char color);

private:
  std::vector<Body*> bodies_;

  struct RenderBuffer {
    std::vector<unsigned char> fill;
    std::vector<float> depth;

    int width, height;

    RenderBuffer(int width, int height) {
      this->width = width;
      this->height = height;

      auto n_pix = width * height;
      fill.resize(n_pix);
      depth.resize(n_pix);
    }

    void Clear() {
      std::fill(fill.begin(), fill.end(), 0);
      std::fill(depth.begin(), depth.end(), 100.f);
    }
  };

  RenderBuffer buff;
};
